//





//  RACSequenceVC.m
//  ReactiveObjCDemo
//
//  Created by app on 2017/12/27.
//  Copyright © 2017年 xth. All rights reserved.
//

#import "RACSequenceVC.h"
#import <objc/runtime.h>

@interface RACSequenceVC ()

@end

@implementation RACSequenceVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self createSequence];
    
    [self createSequenceOperation];
}

/*
 RACSequence:RAC中的集合类，用于代替NSAarray,NSDictionary,可以用它来快速便利数组和字典
 第一步：把数组转换成RACSequence numbers.rac_sequence
 第二步：把集合RACSequence转换RACSignal信号类，numbers.rac_sequence.signal
 第三部：订阅信号，激活信号，会自动把集合中的所有值，遍历出来。
 */

- (void)createSequence {
    
    NSArray *array = @[@(1), @(2), @(3), @(4), @(5), @(6)];
    
    NSDictionary *dict = @{
                           @"name": @"jack",
                           @"age": @(18)
                           };
    
    [array.rac_sequence.signal subscribeNext:^(id  _Nullable x) {
        NSLog(@"数组当前的值：%@", x);
    }];
    
    [dict.rac_sequence.signal subscribeNext:^(id  _Nullable x) {
        RACTupleUnpack(NSString *key, NSString *value) = x;
        NSLog(@"key：%@, value：%@", key, value);
        NSLog(@"x:%@,type:%@",x,NSStringFromClass(object_getClass(x)));
    }];
}


//可以对数组进行map,filter,reduce,skip,take,contact..操作
- (void)createSequenceOperation {
    
    NSArray *array = @[@(1), @(2), @(3), @(4), @(5), @"逗比"];
    
    RACSequence *sequence = [array rac_sequence];
    
    [[sequence.signal map:^id _Nullable(NSNumber * _Nullable value) {
        return value;
    }] subscribeNext:^(id  _Nullable x) {
        NSLog(@"---%@", x);
    }];
    
//    id mapData = [sequence map:^id _Nullable(id  _Nullable value) {
//
//    }];
    
    
}








- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
